package com.chis.jxc;

import com.chis.jm.bean.jxc.CntstmInfoBean;
import com.chis.jm.bean.ll.RedisPointBean;
import com.chis.jmdatatimer.comm.JedisConnect;
import com.chis.jmdatatimer.comm.JedisSerializeUtil;
import com.chis.jmdatatimer.comm.TxMgmtModule;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import redis.clients.jedis.ShardedJedis;
import redis.clients.jedis.ShardedJedisPool;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年03月19日
 */
public class TestJxc {
    /**
     * 1查询
     * 2修改
     * @param args
     */
    public static void main(String[] args) {
        try {
            String opt = args[0];
            String unitCode = args[1];
            String guid = args[2];


            if(opt.equals("1")){
                ShardedJedisPool jedisPool = JedisConnect.getInstance().jedisPoolJxc;
                ShardedJedis jedis = jedisPool.getResource();
                jedis.select(1);
                List<CntstmInfoBean> cntstmInfoBeans = (List<CntstmInfoBean>) JedisSerializeUtil.unserialize(jedis.get(unitCode.toString().getBytes()));
                if (cntstmInfoBeans != null && cntstmInfoBeans.size() > 0){
                    System.out.println("查到");
                    for (CntstmInfoBean cntstmInfoBean : cntstmInfoBeans) {
                        if(guid.equals("-1") || cntstmInfoBean.getGuid().equals(guid)){
                            System.out.println("===============");
                            /** 编码*/
                            System.out.println("编码:"+cntstmInfoBean.getGuid());
                            /** 单位编码 */
                            System.out.println("单位编码:"+cntstmInfoBean.getUnitCode());
                            /** 仓库编码 */
                            System.out.println("仓库编码:"+cntstmInfoBean.getStorageCode());
                            /** 仓库名称 */
                            System.out.println("仓库名称:"+cntstmInfoBean.getStorageName());
                            /** 药品编码*/
                            System.out.println("药品编码:"+cntstmInfoBean.getMetaralCode());
                            /** 疫苗类别编码（6位）*/
                            System.out.println("疫苗类别编码:"+cntstmInfoBean.getBacttype());
                            /** 疫苗物资名称*/
                            System.out.println("疫苗物资名称:"+cntstmInfoBean.getMetaralName());
                            /** 拼音码*/
                            System.out.println("拼音码:"+cntstmInfoBean.getSplat());
                            /** 规格 */
                            System.out.println("规格:"+cntstmInfoBean.getVaccspe());
                            /** 剂型 */
                            System.out.println("剂型:"+cntstmInfoBean.getPreform());
                            /**　计量单位*/
                            System.out.println("计量单位:"+cntstmInfoBean.getMeasunit());
                            /** 物资属性 */
                            System.out.println("物资属性:"+cntstmInfoBean.getVaccprop());
                            /** 包装类型*/
                            System.out.println("包装类型:"+cntstmInfoBean.getPackageType());
                            String packageType;
                            /** 厂家编码（6位）*/
                            System.out.println("厂家编码:"+cntstmInfoBean.getCorpcode());
                            /** 厂家名称*/
                            System.out.println("厂家名称:"+cntstmInfoBean.getCorpname());
                            /** 是否进口疫苗*/
                            System.out.println("是否进口疫苗:"+cntstmInfoBean.getImportbat());
                            /** 批号 */
                            System.out.println("批号:"+cntstmInfoBean.getBatnmb());
                            /** 生产日期 */
                            System.out.println("生产日期:"+cntstmInfoBean.getProduceDate());
                            /** 失效日期 */
                            System.out.println("失效日期:"+cntstmInfoBean.getInd());
                            /** 库存数量 */
                            System.out.println("库存数量:"+cntstmInfoBean.getStmCnt());
                            /** 最后入库单价 */
                            System.out.println("最后入库单价:"+cntstmInfoBean.getPrice());
                            /** 零售价 */
                            System.out.println("零售价:"+cntstmInfoBean.getRetailPrice());
                            /** 人份数*/
                            System.out.println("人份数:"+cntstmInfoBean.getPsncent());

                        }

                    }
                }else{
                    System.out.println("没查到");
                }
                jedis.close();
            } else if(opt.equals("2")){
                ShardedJedisPool jedisPool = JedisConnect.getInstance().jedisPoolJxc;
                ShardedJedis jedis = jedisPool.getResource();
                jedis.select(3);
                Map<String,String> elecCodeMap = jedis.hgetAll(unitCode);
                for(String s : elecCodeMap.keySet()){
                    System.out.println("key:"+s);
                    System.out.println("value:"+elecCodeMap.get(s));
                }
//                Set<String> hkeys = jedis.hkeys("*");
//                for(String key: hkeys){
//                    Map<String,String> redisMap = jedis.hgetAll(key);
//                    System.out.println("===========================");
//                    for(String s : redisMap.keySet()){
//                        System.out.println(s);
//                        System.out.println(redisMap.get(s));
//                        System.out.println("============");
//                    }
//                }
                jedis.close();
            } else if(opt.equals("3")){
                ShardedJedisPool jedisPool = JedisConnect.getInstance().jedisPoolJxc;
                ShardedJedis jedis = jedisPool.getResource();
                //删除已扫电子监管码
                jedis.select(3);
                Map<String,String> elecCodeMap = jedis.hgetAll(unitCode);
                Map<String,String> newmap = new HashMap<>();
                for(String s : elecCodeMap.keySet()){
                    if(!s.equals(guid)){
                        newmap.put(s,elecCodeMap.get(s));
                    }
                }
                jedis.del(unitCode);
                jedis.hmset(unitCode,newmap);
                jedis.expire(unitCode,1209600);
                jedis.close();
            } else if(opt.equals("4")){
                //内存库查询
                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
                context.start();

                System.out.println("疫苗库存内存库检测：");
                TxMgmtModule salRemote = (TxMgmtModule)context.getBean("TxMgmtModule");
                salRemote.cntstmInfoSearch("32");

            }else if(opt.equals("5")){
                //内存库同步
                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
                context.start();

                System.out.println("疫苗库存内存库处理开始");
                TxMgmtModule salRemote = (TxMgmtModule)context.getBean("TxMgmtModule");
                System.out.println("3200");
                salRemote.cntstmInfoSync("3200");
                System.out.println("3201");
                salRemote.cntstmInfoSync("3201");
                System.out.println("3202");
                salRemote.cntstmInfoSync("3202");
                System.out.println("3203");
                salRemote.cntstmInfoSync("3203");
                System.out.println("3204");
                salRemote.cntstmInfoSync("3204");
                System.out.println("3205");
                salRemote.cntstmInfoSync("3205");
                System.out.println("3206");
                salRemote.cntstmInfoSync("3206");
                System.out.println("3207");
                salRemote.cntstmInfoSync("3207");
                System.out.println("3208");
                salRemote.cntstmInfoSync("3208");
                System.out.println("3209");
                salRemote.cntstmInfoSync("3209");
                System.out.println("3210");
                salRemote.cntstmInfoSync("3210");
                System.out.println("3211");
                salRemote.cntstmInfoSync("3211");
                System.out.println("3212");
                salRemote.cntstmInfoSync("3212");
                System.out.println("3213");
                salRemote.cntstmInfoSync("3213");
                System.out.println("疫苗库存内存库处理结束");

            } else if(opt.equals("6")){
                ShardedJedisPool jedisPool = JedisConnect.getInstance().jedisPoolJxc;
                ShardedJedis jedis = jedisPool.getResource();
                //删除已扫电子监管码
                jedis.select(3);
                Map<String,String> newmap = new HashMap<>();
                // guid = "81F6EB27-1F23-F7FB-D14D-39DD112AE9DD=81901934035435985860,81901934041295685704,81901934035438277381,81901934033625121264,81901934041291673898,81901934041310266037,81901934041303052866,81901934041293058398,81901934041302320316,81901934041305764156,81901934041295966052,81901934041312674900,81901934041308598767,81901934041317512887,81901934041316260484,81901934041313090187,81901934041297069913,81901934041317294945,81901934041297460934,81901934041315962491";
                for(String tm : guid.split("#")){
                    String[] t1 = tm.split("=");
                    newmap.put(t1[0],t1[1]);
                }
                jedis.del(unitCode);
                jedis.hmset(unitCode,newmap);
                jedis.expire(unitCode,1209600);
                jedis.close();
            }

        } catch (Exception e){
            e.printStackTrace();
        }



    }


}
